'''
Created on 2013-02-27

@author: Nich
'''
import unittest
from graph.graphnodes import *


def create_test_room():
    gryff_cr = Room("gryffindore_common_room")
    
    
    n = gryff_cr.add_location("north")
    e = gryff_cr.add_location("east")
    s = gryff_cr.add_location("south")
    w = gryff_cr.add_location("west")
    
    Link(n, e)
    Link(n, w)
    Link(n, s)
    
    Link(e, w)
    
    Link(s, e)
    Link(s, w)
    
    print(e.links)
    
    print(gryff_cr.contents)
    
    n.add_object(Object("chair1", "chair1", "chair"))
    gryff_cr.contents["north"].add_object(Object("chair2", "chair2", "chair"))
    gryff_cr.contents["north"].add_object(Object("chair3", "chair3", "chair"))
    gryff_cr.contents["north"].add_object(Object("chair4", "chair4", "chair"))
    gryff_cr.contents["north"].add_object(Object("chair5", "chair5", "chair"))
    
    print(gryff_cr.contents["north"].contents)
    return gryff_cr

def create_very_large_room():
    large_room = Room("a_large_room")
    
    

class GraphNodesTest(unittest.TestCase):

    def setUp(self):
        pass


    def tearDown(self):
        pass


    def test_nodes_linked(self):
        a = Node()
        b = Node()
        link = Link(a, b)
        
        self.assertEquals(a, link.get_neighbour(b))
        self.assertEquals(b, link.get_neighbour(a))
        
    def test_bad_link(self):
        a = Node()
        b = Node()
        c = Node()
        
        link = Link(a, b)
        link2 = Link(a, c)
        
        self.assertEquals(a, link.get_neighbour(b))
        self.assertEquals(b, link.get_neighbour(a))
        
        self.assertEquals(a, link2.get_neighbour(c))
        self.assertEquals(c, link2.get_neighbour(a))
        
        with self.assertRaises(Exception):
            link2.get_neighbour(b)
            link.get_neighbour(c)

    def test_link_to_self_not_permitted(self):
        a = Node()
        with self.assertRaises(Exception):
            Link(a, a)
        
        
        
    
    
    def test_room(self):
        gryff_cr = create_test_room()
        self.assertEqual(gryff_cr.name, "gryffindore_common_room")
        
    def test_links(self):
        gryff_cr = create_test_room()
        s = gryff_cr.contents["south"]
        south_neighbours = sorted([n.data.name for n in s.get_neighbours()])
        print(south_neighbours)
        
        self.assertEqual(south_neighbours, ["east", "north", "west"])
        
    
        
        
if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()